<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span>
</span><span id="line-3"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-4"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- Module      :  System.Exit</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2001</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-8"></span><span class="hs-comment">--</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-12"></span><span class="hs-comment">--</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Exiting the program.</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-16"></span><span>
</span><span id="line-17"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.Exit</span><span>
</span><span id="line-18"></span><span>    </span><span class="hs-special">(</span><span>
</span><span id="line-19"></span><span>      </span><span class="annot"><a href="GHC.IO.Exception.html#ExitCode"><span class="hs-identifier">ExitCode</span></a></span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Exception.html#ExitSuccess"><span class="hs-identifier">ExitSuccess</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.IO.Exception.html#ExitFailure"><span class="hs-identifier">ExitFailure</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-20"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Exit.html#exitWith"><span class="hs-identifier">exitWith</span></a></span><span>
</span><span id="line-21"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Exit.html#exitFailure"><span class="hs-identifier">exitFailure</span></a></span><span>
</span><span id="line-22"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Exit.html#exitSuccess"><span class="hs-identifier">exitSuccess</span></a></span><span>
</span><span id="line-23"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.Exit.html#die"><span class="hs-identifier">die</span></a></span><span>
</span><span id="line-24"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.IO.html"><span class="hs-identifier">System.IO</span></a></span><span>
</span><span id="line-27"></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.html"><span class="hs-identifier">GHC.IO</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html"><span class="hs-identifier">GHC.IO.Exception</span></a></span><span>
</span><span id="line-30"></span><span>
</span><span id="line-31"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-32"></span><span class="hs-comment">-- exitWith</span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span class="hs-comment">-- | Computation 'exitWith' @code@ throws 'ExitCode' @code@.</span><span>
</span><span id="line-35"></span><span class="hs-comment">-- Normally this terminates the program, returning @code@ to the</span><span>
</span><span id="line-36"></span><span class="hs-comment">-- program's caller.</span><span>
</span><span id="line-37"></span><span class="hs-comment">--</span><span>
</span><span id="line-38"></span><span class="hs-comment">-- On program termination, the standard 'Handle's 'stdout' and</span><span>
</span><span id="line-39"></span><span class="hs-comment">-- 'stderr' are flushed automatically; any other buffered 'Handle's</span><span>
</span><span id="line-40"></span><span class="hs-comment">-- need to be flushed manually, otherwise the buffered data will be</span><span>
</span><span id="line-41"></span><span class="hs-comment">-- discarded.</span><span>
</span><span id="line-42"></span><span class="hs-comment">--</span><span>
</span><span id="line-43"></span><span class="hs-comment">-- A program that fails in any other way is treated as if it had</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- called 'exitFailure'.</span><span>
</span><span id="line-45"></span><span class="hs-comment">-- A program that terminates successfully without calling 'exitWith'</span><span>
</span><span id="line-46"></span><span class="hs-comment">-- explicitly is treated as if it had called 'exitWith' 'ExitSuccess'.</span><span>
</span><span id="line-47"></span><span class="hs-comment">--</span><span>
</span><span id="line-48"></span><span class="hs-comment">-- As an 'ExitCode' is not an 'IOError', 'exitWith' bypasses</span><span>
</span><span id="line-49"></span><span class="hs-comment">-- the error handling in the 'IO' monad and cannot be intercepted by</span><span>
</span><span id="line-50"></span><span class="hs-comment">-- 'catch' from the &quot;Prelude&quot;.  However it is a 'Control.Exception.SomeException', and can</span><span>
</span><span id="line-51"></span><span class="hs-comment">-- be caught using the functions of &quot;Control.Exception&quot;.  This means</span><span>
</span><span id="line-52"></span><span class="hs-comment">-- that cleanup computations added with 'Control.Exception.bracket'</span><span>
</span><span id="line-53"></span><span class="hs-comment">-- (from &quot;Control.Exception&quot;) are also executed properly on 'exitWith'.</span><span>
</span><span id="line-54"></span><span class="hs-comment">--</span><span>
</span><span id="line-55"></span><span class="hs-comment">-- Note: in GHC, 'exitWith' should be called from the main program</span><span>
</span><span id="line-56"></span><span class="hs-comment">-- thread in order to exit the process.  When called from another</span><span>
</span><span id="line-57"></span><span class="hs-comment">-- thread, 'exitWith' will throw an 'ExitException' as normal, but the</span><span>
</span><span id="line-58"></span><span class="hs-comment">-- exception will not cause the process itself to exit.</span><span>
</span><span id="line-59"></span><span class="hs-comment">--</span><span>
</span><span id="line-60"></span><span id="local-6989586621679563944"><span class="annot"><a href="System.Exit.html#exitWith"><span class="hs-identifier hs-type">exitWith</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html#ExitCode"><span class="hs-identifier hs-type">ExitCode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679563944"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-61"></span><span id="exitWith"><span class="annot"><span class="annottext">exitWith :: forall a. ExitCode -&gt; IO a
</span><a href="System.Exit.html#exitWith"><span class="hs-identifier hs-var hs-var">exitWith</span></a></span></span><span> </span><span class="annot"><span class="annottext">ExitCode
</span><a href="GHC.IO.Exception.html#ExitSuccess"><span class="hs-identifier hs-var">ExitSuccess</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExitCode -&gt; IO a
forall e a. Exception e =&gt; e -&gt; IO a
</span><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-var">throwIO</span></a></span><span> </span><span class="annot"><span class="annottext">ExitCode
</span><a href="GHC.IO.Exception.html#ExitSuccess"><span class="hs-identifier hs-var">ExitSuccess</span></a></span><span>
</span><span id="line-62"></span><span class="annot"><a href="System.Exit.html#exitWith"><span class="hs-identifier hs-var">exitWith</span></a></span><span> </span><span id="local-6989586621679563910"><span class="annot"><span class="annottext">code :: ExitCode
</span><a href="#local-6989586621679563910"><span class="hs-identifier hs-var">code</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Exception.html#ExitFailure"><span class="hs-identifier hs-type">ExitFailure</span></a></span><span> </span><span id="local-6989586621679563909"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679563909"><span class="hs-identifier hs-var">n</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-63"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679563909"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%2F%3D"><span class="hs-operator hs-var">/=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExitCode -&gt; IO a
forall e a. Exception e =&gt; e -&gt; IO a
</span><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-var">throwIO</span></a></span><span> </span><span class="annot"><span class="annottext">ExitCode
</span><a href="#local-6989586621679563910"><span class="hs-identifier hs-var">code</span></a></span><span>
</span><span id="line-64"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO a
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; String
-&gt; String
-&gt; Maybe CInt
-&gt; Maybe String
-&gt; IOError
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#InvalidArgument"><span class="hs-identifier hs-var">InvalidArgument</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;exitWith&quot;</span></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ExitFailure 0&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe String
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-65"></span><span>
</span><span id="line-66"></span><span class="hs-comment">-- | The computation 'exitFailure' is equivalent to</span><span>
</span><span id="line-67"></span><span class="hs-comment">-- 'exitWith' @(@'ExitFailure' /exitfail/@)@,</span><span>
</span><span id="line-68"></span><span class="hs-comment">-- where /exitfail/ is implementation-dependent.</span><span>
</span><span id="line-69"></span><span id="local-6989586621679563932"><span class="annot"><a href="System.Exit.html#exitFailure"><span class="hs-identifier hs-type">exitFailure</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679563932"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-70"></span><span id="exitFailure"><span class="annot"><span class="annottext">exitFailure :: forall a. IO a
</span><a href="System.Exit.html#exitFailure"><span class="hs-identifier hs-var hs-var">exitFailure</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExitCode -&gt; IO a
forall a. ExitCode -&gt; IO a
</span><a href="System.Exit.html#exitWith"><span class="hs-identifier hs-var">exitWith</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; ExitCode
</span><a href="GHC.IO.Exception.html#ExitFailure"><span class="hs-identifier hs-var">ExitFailure</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-71"></span><span>
</span><span id="line-72"></span><span class="hs-comment">-- | The computation 'exitSuccess' is equivalent to</span><span>
</span><span id="line-73"></span><span class="hs-comment">-- 'exitWith' 'ExitSuccess', It terminates the program</span><span>
</span><span id="line-74"></span><span class="hs-comment">-- successfully.</span><span>
</span><span id="line-75"></span><span id="local-6989586621679563904"><span class="annot"><a href="System.Exit.html#exitSuccess"><span class="hs-identifier hs-type">exitSuccess</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679563904"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-76"></span><span id="exitSuccess"><span class="annot"><span class="annottext">exitSuccess :: forall a. IO a
</span><a href="System.Exit.html#exitSuccess"><span class="hs-identifier hs-var hs-var">exitSuccess</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ExitCode -&gt; IO a
forall a. ExitCode -&gt; IO a
</span><a href="System.Exit.html#exitWith"><span class="hs-identifier hs-var">exitWith</span></a></span><span> </span><span class="annot"><span class="annottext">ExitCode
</span><a href="GHC.IO.Exception.html#ExitSuccess"><span class="hs-identifier hs-var">ExitSuccess</span></a></span><span>
</span><span id="line-77"></span><span>
</span><span id="line-78"></span><span class="hs-comment">-- | Write given error message to `stderr` and terminate with `exitFailure`.</span><span>
</span><span id="line-79"></span><span class="hs-comment">--</span><span>
</span><span id="line-80"></span><span class="hs-comment">-- @since 4.8.0.0</span><span>
</span><span id="line-81"></span><span id="local-6989586621679563929"><span class="annot"><a href="System.Exit.html#die"><span class="hs-identifier hs-type">die</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679563929"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-82"></span><span id="die"><span class="annot"><span class="annottext">die :: forall a. String -&gt; IO a
</span><a href="System.Exit.html#die"><span class="hs-identifier hs-var hs-var">die</span></a></span></span><span> </span><span id="local-6989586621679563901"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679563901"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStrLn"><span class="hs-identifier hs-var">hPutStrLn</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="GHC.IO.StdHandles.html#stderr"><span class="hs-identifier hs-var">stderr</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679563901"><span class="hs-identifier hs-var">err</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO a -&gt; IO a
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; m b -&gt; m b
</span><a href="GHC.Base.html#%3E%3E"><span class="hs-operator hs-var">&gt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="System.Exit.html#exitFailure"><span class="hs-identifier hs-var">exitFailure</span></a></span><span>
</span><span id="line-83"></span></pre></body></html>